import Controller from 'castle-koa/dist/lib/controller'
import User from './User';
//目录管理
/**,
   //NavID NAID BIGINT ,
   //用户ID UID BIGINT ,
   //栏目名称 Tile CHAR(50) ,
   //创建时间 CTime TIMESTAMP ,
   //状态 Status TINYINT(1) ,
   */
export default class Nav extends Controller{
    async selectAllNav(post){
        return await this.M("Nav").select();
    }
    async updateNav(post){
        console.log(post.user.UID)
        const a = await this.M("Nav").where({NAID:post.NAID}).save({Tile:post.Tile,UID:post.user.UID});
       
        if(a!=1){
            return {
                status:false,
                message:"修改失败！"
            }
        }
        return{
            status:true,
            message:"修改成功！"
        }
    }
    async deleteNav(post){
        console.log(post)
        const a = await this.M("Nav").where({NAID:post.NAID}).del();
        if(a!=1){
            return{
                status:false,
                message:"删除失败！"
            }
        }
        return {
            status:true,
            message:"删除成功！"
        }
    }
    async addNav(post){
        const re = await this.M("Nav").where({Tile:post.Tile}).find();
        if(re!=null){
            return {
                status:false,
                message:"标题已存在！"
            }
        }
        const date = new Date().toLocaleDateString()
        const a = await this.M("Nav").add({Tile:post.Tile,UID:post.UID,CTime:date});
        if(a==null){
            return {
                status:false,
                message:"新增失败！"
            }
        }
        return{
            status:true,
            message:"新增成功！"
        }
    }
}